﻿using Nemerle.ComputationExpressions;

using System;
using System.Collections.Generic;
using System.Linq;

class LambdaYield
{
  public Yield() : void 
  {
    def lambda = x => comp list { 
      foreach(y in x) when(y%2==0) yield  y
    };
    
    Console.WriteLine(lambda(array[1,2,3,4]));
    // [2,4]
    
    def collection = comp list { 
      yieldcomp $[0..3]; // instead of 'foreach(i in $[0..3]) yield i;'
      yield -1;
      yield -2;
    };
    
    Console.WriteLine(collection);
    // [0,1,2,3,-1,-2]
  }
}